"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Service extends Model {
    //售后模型
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      Service.belongsTo(models.Client, {
        foreignKey: "client_id",
        onDelete: "SET DEFAULT",
      });
      Service.belongsTo(models.Project, {
        foreignKey: "project_id",
        onDelete: "SET DEFAULT",
      });
      Service.hasMany(models.ServiceDoc, {
        foreignKey: "service_id",
      });
      Service.belongsTo(models.Staff, {
        foreignKey: "checker_id",
        as: "checker",
        onDelete: "CASCADE",
      });
      // Service.belongsTo(models.Contract,{
      //   foreignKey:'contract_id'
      // })
      Service.belongsTo(models.Shop, {
        foreignKey: "shop_id",
        allowNull: true,
      });
      // define association here
    }
  }
  Service.init(
    {
      purchase_time: DataTypes.DATE,
      service_start_time: DataTypes.DATE,
      service_end_time: DataTypes.DATE,
      warranty: DataTypes.INTEGER,
      product_type: DataTypes.STRING,
      sequence: DataTypes.STRING,
      description: DataTypes.TEXT,
      approval_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      },
      check_sug: DataTypes.STRING,
      // check_staffs:DataTypes.TEXT
    },
    {
      sequelize,
      modelName: "Service",
      tableName: "services",
    }
  );
  return Service;
};
